<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>工单管理</title>
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <link rel="stylesheet" href="../css/page_css/util.css">
</head>

<body>
	<div class="mui-content">
		<ul class="mui-table-view01">
			 <li class="search-cell">
			 	<div class="mui-input-row mui-search">
					<input type="search" id="searchText" onclick="openSearchWin()" readonly="readonly" class="mui-input-clear" placeholder="请输入关键字" ><span class="mui-icon mui-icon-clear mui-hidden"></span><span class="mui-placeholder"><span></span></span>
				</div>
				<div class="mui-btn mui-btn-primary" tapmode onclick="Search()">
					搜索
				</div>
			 </li>
		</ul>
		<div class="mui-segmented-control mui-segmented-control-inverted mui-segmented-control-primary segmentedControl">
			<a href="#" class="mui-control-item text_hidden" tapmode onclick="openSaveWin('work_order_sel_address','选择位置')" id="LocationName">位置</a>
			<a href="#" class="mui-control-item text_hidden" tapmode onclick="openSaveWin('work_order_sel_property','选择资产')" id="propertyName">资产</a>
			<a href="#" class="mui-control-item text_hidden" tapmode onclick="openSaveWin('work_order_sel_manager','选择人员',{manager: true})" id="managerName">主管人</a>
			<a href="#" class="mui-control-item text_hidden" tapmode onclick="openSaveWin('work_order_sel_status','选择状态')" id="statusName">状态</a>
		</div>
		<ul class="check_search_list">
			<li id="mineOrder" onclick="checkOrder('mineOrder')">
				我的工单
			</li>
			<li id="historyOrder" onclick="checkOrder('historyOrder')">
				历史工单
			</li>
		</ul>
		<div id="ordrListsContent">
			<script type="text/template" id="itemslist">
  			{{each datas as item i}}
  			<div class="mui-card">
  				<ul class="mui-table-view mui-table-view-chevron">
  					<li class="mui-table-view-cell mui-collapse">
  						{{if item.isTimeOut == '1'}}
  						<a class="mui-navigate-right zdmb" href="#"><img src="../image/warning.png" style="width:0.8rem;display:inline-block;margin-right:0.2rem;"/>工单：{{item.wonum}}
  						{{else}}
  						<a class="mui-navigate-right zdmb" href="#">工单：{{item.wonum}}
  						{{/if}}
  							<span class="mui-badge mui-badge-inverted">负责人:{{item.userName}}</span>
  							<div style="font-size: .6rem;">位置：{{item.location}}</div>
  						</a>
  						<a class="zdmb" href="#" style="white-space: initial;font-size: .6rem;padding-top: 2px!important;">工单标题：{{item.wonumDesc}}</a>
  						<ul class="mui-table-view mui-table-view-chevron">
  							<li class="mui-table-view-cell">工单标题：{{item.wonumDesc}}</li>
  							<li class="mui-table-view-cell">位置名称：{{item.locationName}}</li>
  							<li class="mui-table-view-cell">资产：{{item.assetnum}}</li>
  							<li class="mui-table-view-cell">资产名称：{{item.assetnumName}}</li>
  							<li class="mui-table-view-cell">维修区域：{{item.cRegion}}</li>
  							<li class="mui-table-view-cell">状态：{{item.status}}</li>
  							<li class="mui-table-view-cell">计划开始时间：{{item.schedstart}}</li>
  							<li class="mui-table-view-cell">计划结束时间：{{item.schedfinish}}</li>
  						</ul>
  					</li>
  				</ul>
  				<div class="mui-card-footer">
  				{{if item.worktype == 'T04' }}
  					<a class="mui-card-link" tapmode onclick="openSaveWin('tmp_order', '巡点检项',{workorderid: {{item.workorderid}}})">巡点检项</a>
            <a class="mui-card-link" tapmode onclick="openOrderDetailWin('{{item.workorderid}}', '{{item.wonum}}',api.pageParam.orderType)">查看详情</a>
  				{{else if item.home == 'home' && item.worktype == 'T03'}}
  					<a class="mui-card-link" tapmode onclick="openFile(api.pageParam.cRegion,{{item.workorderid}})">查看TIS</a>
  				{{else}}
  					<a class="mui-card-link" tapmode onclick="openOrderDetailWin('{{item.workorderid}}', '{{item.wonum}}',api.pageParam.orderType)">查看详情</a>
  				{{/if}}
  					<a class="mui-card-link" tapmode onclick="openTastWin('approval_record','审批记录', {wonum: {{item.wonum}}})">审批记录</a>
  				</div>
  			</div>
  			{{/each}}
      </script>
		</div>

	</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script src="../script/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../script/common.js" type="text/javascript" charset="utf-8"></script>
<script src="../script/template.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	var cRegion = '', assetnum = '', userID = '',
	statusId, searchText, isMine = 0, isHistory = 0, UISearchBar = null;
	apiready = function () {
		UISearchBar = api.require('UISearchBar');
		if (api.pageParam.searchText){
			$api.val($api.byId('searchText'), api.pageParam.searchText)
		}
    if(api.pageParam.wonum){
      $api.val($api.byId('searchText'), api.pageParam.wonum)
		}
		if(api.pageParam.home == 'home'){
			cRegion = api.pageParam.cRegion;
			$api.html($api.byId('LocationName'),api.pageParam.cRegion || '暂无位置信息');
//			$api.addCls($api.byId('LocationName'),'mui-active');
			statusId = '等待计划,等待批准,进行中,已批准';
			$api.html($api.byId('statusName'),'等待计划,等待批准,进行中,已批准');
		}
		onLoadData(curPage,false);
		scrollToBottomHandler(function() {
			if (!loadEnd) { // 没有结束时继续加载
				curPage++;
				onLoadData(curPage,true);
			} else { // 告诉到底了
				EndToast('到底了');
			}
		})
		Refresh(function() {
			tjsearch();
		});
		api.addEventListener({
		    name: 'LocactionId'
		}, function(ret, err) {
			cRegion = ret.value.locationName;
			$api.html($api.byId('LocationName'),ret.value.locationName)
			tjsearch();
		});
		api.addEventListener({
		    name: 'PropertyId'
		}, function(ret, err) {
			assetnum = ret.value.propertyId;
			$api.html($api.byId('propertyName'),ret.value.description)
			tjsearch();
		});
		api.addEventListener({
		    name: 'ManagerCh'
		}, function(ret, err) {
			userID = ret.value.userID;
			$api.html($api.byId('managerName'),ret.value.userName)
			tjsearch();
		});
	    // 选择状态
	    api.addEventListener({
	        name: 'status'
	    }, function(ret, err) {
	      statusId = ret.value.statusName;
	      $api.html($api.byId('statusName'),ret.value.statusName)
	      tjsearch();
	    });
		api.parseTapmode();
	}
	function openOrderDetailWin(workorderid, wonum, orderType){
    if (api.pageParam.checkIsException) {
      openWin('tmp_order_abnormal_detail','',{
  	        background: '#6098de',
  	        color: '#fff',
  	        rightButtons:[{
  	        	// iconPath:"widget://image/operate-icon.png"
  	        }]
  	    },{
  	    	workorderid:workorderid,
  	    	wonum: wonum,
  	    	orderType: orderType
  	    })
    } else {
      openWin('work_order_manage_detail','工单详细信息',{
  	        background: '#6098de',
  	        color: '#fff',
  	        rightButtons:[{
  	        	iconPath:"widget://image/operate-icon.png"
  	        }]
  	    },{
  	    	workorderid:workorderid,
  	    	wonum: wonum,
  	    	orderType: orderType
  	    })
    }
	}
	function onLoadData (page,load) {
		searchText = getVal('searchText')
    let params = {
      wonum: searchText,
      orderType: api.pageParam.orderType,
      isMine: isMine,
      isHistory: isHistory,
      assetnum: assetnum,
      supervisor: userID,
      status: statusId,
      pageNo: curPage,
      pageSize: 10,
      isTodo: api.pageParam.isTodo || 0,
      checkIsException: api.pageParam.checkIsException || 0
    }
    if (api.pageParam.checkIsException) {
      params.location = ''
      params.cRegion = cRegion || ''
    } else {
      params.location = cRegion || ''
      params.cRegion = ''
    }
    if (api.pageParam.isFromTpmPage) {
      params.cRegion = api.pageParam.cRegion
    }
		ajaxrd("queryOrderList", params, function(ret, err) {
			api.refreshHeaderLoadDone();
			var newArr = ret.list;
			for (var i=0;i<newArr.length;i++) {
				newArr[i].home=api.pageParam.home;
			}
			AddData('itemslist','ordrListsContent',newArr,load);
			if (ret.list.length < 10) {
				loadEnd = true
			}
		})
	}
	function checkOrder (id) {
		if ($api.hasCls($api.byId(id),'active')) {
			$api.removeCls($api.byId(id),'active');
			if(id == 'historyOrder') { //点击历史
				isHistory = 0;
			} else if (id == 'mineOrder') {
				isMine = 0;
			}
		} else {
			$api.addCls($api.byId(id),'active');
			if(id == 'historyOrder') { //点击历史
				isHistory = 1;
			} else if (id == 'mineOrder') {
				isMine = 1;
			}
		}
		tjsearch();
	}
	function openFile (location1,workorderid) {
		ajaxrd("queryTisDocinfoId", {
            location: location1,
            workorderid: workorderid
        }, function(ret, err) {
//          docinfoid
			var localFileName = guid() + '.xls';
			showExcelFile(baseURL + 'downloadFile?docinfoid=' + ret.docinfoid, localFileName)
        })
	}
	function openSearchWin(){
		UISearchBar.open({
		    placeholder: '请输入搜索关键字',
		    historyCount: 10,
		    showRecordBtn: false,
		    dataBase: 'workOrder',
		    texts: {
		        cancelText: '取消',
		        clearText: '清除搜索记录'
		    },
		    styles: {
		        navBar: {
		            bgColor: '#3398dc',
		            borderColor: '#ccc'
		        },
		        searchBox: {
		            bgImg: '',
		            color: '#000',
		            height: 35,
		            size: 13
		        },
		        cancel: {
		            bg: 'rgba(0,0,0,0)',
		            color: '#fff',
		            size: 15
		        },
		        list: {
		            color: '#696969',
		            bgColor: '#FFFFFF',
		            borderColor: '#eee',
		            size: 15
		        },
		        clear: {
		            color: '#000000',
		            borderColor: '#ccc',
		            size: 15
		        }
		    }
		}, function(ret, err) {
		    if (ret && (ret.eventType == 'search' || ret.eventType == 'history')) {
		        $api.val($api.byId('searchText'),ret.text);
		        Search();
		    } else {
		        //alert(JSON.stringify(err));
		    }
		});
	}
</script>

</html>
